<?php


namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;


class Housing extends Model
{

    protected $table = 'zfm_fangs';

    /**
     * 房源详情
     * @param $id
     * @return mixed
     */
    public static function detail($id)
    {
           return self::where('id','0')->find($id);
    }

    //多条件搜索分页
    public static function getSecharvr($params, $limit, $offset)
    {
        $data['data']= self::when($params, function ($query) use ($params) {
            if (isset($params['location']) && !empty($params['location'])) {
                $query->where('location', 'like', '%' . $params['location'] . '%');
            }
            if (isset($params['price']) && !empty($params['phone'])) {
                $query->Where('price', '>',$params['price']);
            }
        })->offset($offset)->limit($limit)->get();//offset是偏移量; //mit展示每页条数

        $data['total'] =(int)self::when($params, function ($query) use ($params) {
            if (isset($params['location']) && !empty($params['location'])) {
                $query->where('location', 'like', '%' . $params['location'] . '%');
            }
            if (isset($params['price']) && !empty($params['phone'])) {
                $query->Where('price', '>',$params['price']);
            }
        })->count();//offset是偏移量; //mit展示每页条数;

        $data['limit'] =(int)$limit;
        return $data;
    }
}
